/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.impl;

import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.Cancel;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionPath;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionProtocolElement;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionprotocolsPackage;

import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.util.InteractionprotocolsValidator;
import java.util.Map;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.util.EObjectValidator;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Cancel</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * </p>
 *
 * @generated
 */
public class CancelImpl extends CFSNoSyncImpl implements Cancel {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CancelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return InteractionprotocolsPackage.Literals.CANCEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public boolean cancelAndVerification(DiagnosticChain diagnostics, Map context) {
		// TODO: implement this method
		// -> specify the condition that violates the invariant
		// -> verify the details of the diagnostic, including severity and message
		// Ensure that you remove @generated or mark it @generated NOT
		if (validateNotAndParent()) {
			if (diagnostics != null) {
				diagnostics.add
					(new BasicDiagnostic
						(Diagnostic.ERROR,
						 InteractionprotocolsValidator.DIAGNOSTIC_SOURCE,
						 InteractionprotocolsValidator.CANCEL__CANCEL_AND_VERIFICATION,
						 EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "Must not have an And ascendant", EObjectValidator.getObjectLabel(this, context) }), //$NON-NLS-1$ //$NON-NLS-2$
						 new Object [] { this }));
			}
			return false;
		}
		return true;
	}

	 /**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public boolean cancelOrVerification(DiagnosticChain diagnostics, Map context) {
		// TODO: implement this method
		// -> specify the condition that violates the invariant
		// -> verify the details of the diagnostic, including severity and message
		// Ensure that you remove @generated or mark it @generated NOT
		if (validateCancelNotAndParent()) {
			if (diagnostics != null) {
				diagnostics.add
					(new BasicDiagnostic
						(Diagnostic.ERROR,
						 InteractionprotocolsValidator.DIAGNOSTIC_SOURCE,
						 InteractionprotocolsValidator.CANCEL__CANCEL_OR_VERIFICATION,
						 EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "cancelOrVerification", EObjectValidator.getObjectLabel(this, context) }), //$NON-NLS-1$ //$NON-NLS-2$
						 new Object [] { this }));
			}
			return false;
		}
		return true;
	}

		private boolean validateNotAndParent() {
		 
		 InteractionProtocolElement ie = this;
		 InteractionPath ip = null;
		 
		 while(!(ie.eContainer().getClass()==(InteractionProtocolImpl.class))) {
			 if((ie.eContainer().getClass()==(InteractionPathImpl.class))) 
			 {
				 ip = (InteractionPath) ie.eContainer();
			 }
			 else if((ie.eContainer().getClass()==(InteractionProtocolImpl.class))) return false;
			 ie = (InteractionProtocolElement) ip.eContainer();
			 if(ie.getClass()==(AndImpl.class) || ie.getClass()==(OrImpl.class) || ie.getClass()==(MultipleInstanceImpl.class)) return true;
				
			 
		 }
		 return false;
		 
		 
	}
	
	private boolean validateCancelNotAndParent() {
			 
			 InteractionProtocolElement ie = this;
			 InteractionPath ip = null;
			 
			 while(!(ie.eContainer().getClass()==(InteractionProtocolImpl.class))) {
				 if((ie.eContainer().getClass()==(InteractionPathImpl.class))) 
				 {
					 ip = (InteractionPath) ie.eContainer();
				 }
				 else if((ie.eContainer().getClass()==(InteractionProtocolImpl.class))) return false;
				 ie = (InteractionProtocolElement) ip.eContainer();
				 if(ie.getClass()==(AndImpl.class) || ie.getClass()==(OrImpl.class) || ie.getClass()==(MultipleInstanceImpl.class)) return true;
				 
			 }
			 return false;
			 
			 
	}
		
} //CancelImpl
